package com.itguigu.auth.activiti;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  加班流程测试
 */
@SpringBootTest
public class ProcessTestJiaban1 {

    @Autowired
    private RepositoryService repositoryService;


    /**
     * 流程定义部署
     */
    @Test
    public void deployProcess() {
        Deployment deploy = repositoryService
                .createDeployment()
                .addClasspathResource("process/jiaban01.bpmn20.xml")
                .addClasspathResource("process/jiaban.png")
                .name("加班申请流程1")
                .deploy();
        System.out.println(deploy.getId());
        System.out.println(deploy.getName());
        System.out.println("deploy.getKey() = " + deploy.getKey());
    }

    @Autowired
    private RuntimeService runtimeService;

    /**
     * 开启流程实例
     */
    @Test
    public void startUpProcessInstance(){
        ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("jiaban01");
        System.out.println("processInstance1.getProcessDefinitionId() = " + processInstance1.getProcessDefinitionId());
        System.out.println("processInstance1.getProcessDefinitionKey() = " + processInstance1.getProcessDefinitionKey());
        System.out.println("processInstance1.getId() = " + processInstance1.getId());
    }

    @Autowired
    private TaskService taskService;

    @Test
    public void findTaskList() {
        List<Task> list = taskService.createTaskQuery().taskAssignee("hejiabei").list();
        for (Task task : list) {
            System.out.println("task.getProcessDefinitionId() = " + task.getProcessDefinitionId());
            System.out.println("task.getName() = " + task.getName());
            System.out.println("task.getId() = " + task.getId());
            System.out.println("task.getAssignee() = " + task.getAssignee());
        }
    }


}
